<?php

class HomeModel extends AuthModel
{
	private $oAction;
	
	public function __construct()
	{
		parent::__construct();
		
		$this->oAction = "none";
		if (Input::hasRequest("action"))
		{
			$this->oAction = Input::request("action");
			if ($this->oAction == "login")
				$this->oAction = "login";
			else if ($this->oAction == "change_password")
			{
				$pass = Input::request("password");
				$newPass = Input::request("new_password");
				$newRepeatPass = Input::request("new_repeat_password");
				
				$passLen = strlen($pass);
				if ($passLen < 3 || $passLen > 16)
					$this->addError("password", "PASSWORD_ERROR");
				if ($this->hasError()) return;
				
				if (!$this->player()->testPass($pass))
					$this->addError("password", "INVALID_PASSWORD");
				if ($this->hasError()) return;
				
				$passLen = strlen($newPass);
				if ($passLen < 3 || $passLen > 16)
					$this->addError("new_password", "PASSWORD_ERROR");
				if ($this->hasError()) return;

				if ($newPass != $newRepeatPass)
					$this->addError("new_repeat_password", "REPEAT_PASSWORD_ERROR");
					
				if ($this->hasError())
					return;
				
				$this->player()->setPassword($newPass);
			}
			else if ($this->oAction == "about")
			{
				if (!Input::hasRequest("about"))
				{
					$this->addError("about", "");
					return;
				}
				$about = Input::request("about");
				
				$this->player()->setAbout($about);
			}
		}
	}
	
	public function action() { return $this->oAction; }
}

?>